<?php
class ETags extends CWidget {

	var $assets = '';
	var $options;
	var $model;
	var $name;

	/**
	 * Initializes the widget.
	 * This method is called by {@link CBaseController::createWidget}
	 * and {@link CBaseController::beginWidget} after the widget's
	 * properties have been initialized.
	 */
	public function init()
	{
		$this->assets = Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.tags.assets'));

		$cs = Yii::app()->clientScript;
        $cs->registerCoreScript('jquery');
        $cs->registerScriptFile( $this->assets.'/jquery.etags.js' );
        $cs->registerCssFile( $this->assets.'/main.css' );
        
        $options = array(
        	'id'=>$this->id,
        	'model'=>get_class($this->model),
        	'name'=>$this->name,
        );
        $options = CJavaScript::encode($options);
		$cs->registerScript(__CLASS__.'#'.$this->id,"jQuery('#{$this->id}').etags({$options});");

        parent::init();
	}

	/**
	 * Executes the widget.
	 * This method is called by {@link CBaseController::endWidget}.
	 */
	public function run()
	{
		$this->render(__CLASS__, array('id'=>$this->id, 'model'=>$this->model, 'name'=>$this->name));		
	}
	
	
}
?>